package br.com.gaspar.entidade;

import gov.sefaz.utils.entidade.EntidadeBase;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name="tbl_usuario")

@NamedQueries({
	@NamedQuery(name="Usuario.buscarTodos", query="select obj from Usuario obj order by obj.nome"),
	@NamedQuery(name="Usuario.PesquisaPorNome", query="select obj from Usuario obj where obj.nome like :p0 order by obj.nome"),
	@NamedQuery(name="Usuario.naoDeveExistirUsuario", query="select count(obj.id) from Usuario obj where obj.usuario =:p0"),
	@NamedQuery(name="Usuario.buscarPorUsuarioSenha", query="select obj from Usuario obj where obj.usuario =:p0 and obj.senha =:p1")
})
public class Usuario extends EntidadeBase {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@NotEmpty(message="Obrigatório informar o nome!")
	@NotNull(message="Obrigatório informar o nome!")
	@Column(nullable=false, length=100)
	private String nome;
	
	@NotEmpty(message="Obrigatório informar o usuário!")
	@NotNull (message="Obrigatório informar o usuário!")
	@Column(nullable=false, length=20)
	private String usuario;
	
	@Column(nullable=false, length=10)
	private String senha;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date dataCadastro;
	
	public Usuario(){
		
	}

	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public Date getDataCadastro() {
		return dataCadastro;
	}

	public void setDataCadastro(Date dataCadastro) {
		this.dataCadastro = dataCadastro;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Usuario other = (Usuario) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public String getUsuario() {
		return usuario;
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

}
